Hallo NG,
I am new to JavaScript and would really appreciate any help to solve my
problem.
I am using the blow code in my form to validate form fields. What I
would like to accomplish is that if when the list/menu (attribute6)
value is "Ja" then to make the TextField Pas Nr (attribute4)
required. And if when the list/menu (attribute6) value is "Nee" to
make the TextField Pas Nr (attribute4) not required.
I have tried to adjust the code with no success. I give up and hope
that someone can help me to the right direction!
Thank you in advance,
-Platostoteles
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>test</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="41%" border="0" align="center" id="0">
<tr>
<td height="291" colspan="2" align="left" valign="top">
<!-- newsletter -->
<script language="JavaScript" type="text/javascript">
var fieldstocheck = new Array();
fieldnames = new Array();
function checkform() {
for (i=0;i<fieldstocheck.length;i++) {
if
(eval("document.subscribeform.elements['"+fieldstocheck[i]+"'].value")
== "") {
alert("Vul a.u.b. het volgende verplichte veld in:
"+fieldnames[i]);
eval("document.subscribeform.elements['"+fieldstocheck[i]+"'].focus()");
return false;
}
}
if(! compareEmail())
{
alert("De ingevulde Email adressen komen niet overeen");
return false;
}
return true;
}
function addFieldToCheck(value,name) {
fieldstocheck[fieldstocheck.length] = value;
fieldnames[fieldnames.length] = name;
}
function compareEmail()
{
return (document.subscribeform.elements["email"].value ==
document.subscribeform.elements["emailconfirm"].value);
}
</script> <form
action="http://www.whatever.com/newsletter/lists/?p=subscribe"
name="subscribeform" method="post" target="_self">
<div align="left"><font size="2" face="Verdana">
<input type="checkbox" name="list[1]" value=signup checked />
Nieuwsbrief 'Impuls' </font></div>
<div align="left" class="listdescription"> <font size="2"
face="Verdana">
<input type=hidden name="listname[1]" value="Nieuwsbrief
Impuls"/>
</font></div>
<div align="left"><font size="2" face="Verdana">
<input name="list[2]" type="checkbox" value=signup checked
/>
Aanbiedingen voor niet-leden</font></div>
<div align="left" class="listdescription">
<input type=hidden name="listname[2]" value="Aanbiedingen
voor niet-leden"/>
<br>
</div>
<table border=0>
<tr>
<td width="96"><div class="required">Email:</div></td>
<td width="260" class="attributeinput"><input type=text
name=email value="" size="40">
<script language="JavaScript" type="text/javascript">
addFieldToCheck("email","Email");
</script></td>
</tr>
<tr>
<td>Bevestig email:</td>
<td class="attributeinput"><input type=text
name=emailconfirm size="40">
<script language="JavaScript" type="text/javascript">
addFieldToCheck("emailconfirm","Bevestig email");
</script></td>
</tr>
<tr>
<td><font size="2" face="Verdana">Lid:</font></td>
<td class="attributeinput"><font size="2" face="Verdana">
<select name="attribute6" id="select2">
<option value="3">Ja</option>
<option value="4">Nee</option>
</select>
<!--0-->
<script language="JavaScript" type="text/javascript">
addFieldToCheck("attribute6","Lid");
</script>
</font></td>
</tr>
<tr>
<td><div class="required"><font size="2" face="Verdana">Pas
nr.</font></div></td>
<td class="attributeinput"><font size="2" face="Verdana">
<input name="attribute4" type="text" id="PassNr2"
size="15" maxlength="15">
<script language="JavaScript" type="text/javascript">
addFieldToCheck("attribute4","Pas nr");
</script>
</font> </td>
</tr>
<input type=hidden name="htmlemail" value="1">
</table>
<div align="left"><font size="2" face="Verdana"><br>
<input name="subscribe" type="submit" id="subscribe"
value="Aanmelden" onClick="return checkform();">
<br>
<br>
<br>
</font> </div>
</form>
<font size="2" face="Verdana"> </font></td>
</tr>
</table>
</body>
</html>